<?php 
/*
 * form to enter new customer details
*/
//check for a valid session
include("../inc_files/utils/checksession.php");
//include the page header
include("../inc_files/ui/header.php");?>
<title>New customer</title>
<script type="text/javascript">

function validateForm(){
	// reset the styles on the form fields to remove
	// any highlighted errors from previous submissions
	var nuf=document.getElementById("newcustomerform");
	for (var i=0;i<nuf.length;i++)
	  {
		  if(nuf.elements[i].className = "tberror") nuf.elements[i].className = "tbnormal"
	  }

	//check form validation
	var valid = true;
	var errormessage = "This form is not valid. Please correct the following errors.\n";
	
	if(document.getElementById('company').value.length < 1){
		valid=false;
		document.getElementById('company').className = "tberror";
		errormessage += "\nCompany name field empty";
	}
	if(document.getElementById('primarycontactname').value.length < 1){
		valid=false;
		document.getElementById('primarycontactname').className = "tberror";
		errormessage += "\nPrimary contact name field empty";
	}
	if(document.getElementById('primarycontactemail').value.length < 1){
		valid=false;
		document.getElementById('primarycontactemail').className = "tberror";
		errormessage += "\nPrimary contact email field empty";
	}
	if(valid == false){
		alert(errormessage);
		
	}
	return valid;
}

</script>
<link
	rel="stylesheet" type="text/css" href="../styles/style.css">
</head>
<body>
	<?php 	include("../inc_files/ui/menu.php");?>
	<form action="m_addcustomer.php" id="newcustomerform" method="post"
		onsubmit="return validateForm()">
		<table class="inputform">
			<tr>
				<td class="separatorrow" colspan="2">Company:</td>

			</tr>
			<tr>
				<td class="labelcell">Name:</td>
				<td class="formcell"><input type="text" name="company" id="company"
					size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Address:</td>
				<td class="formcell"><textarea rows="5" cols="40" name="address"></textarea>
				</td>
			</tr>

			<tr>
				<td class="labelcell">City:</td>
				<td class="formcell"><input type="text" name="city" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">State:</td>
				<td class="formcell"><input type="text" name="state" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Country:</td>
				<td class="formcell"><input type="text" name="country" size="54">
				</td>
			</tr>
			<tr>
				<td class="labelcell">Postal code:</td>
				<td class="formcell"><input type="text" name="postalcode" size="54">
				</td>
			</tr>
			<tr>
				<td colspan="2" style="height: 30px;"></td>
			</tr>
			<tr>
				<td class="separatorrow" colspan="2">Primary contact</td>

			</tr>
			<tr>
				<td class="labelcell">Name:</td>
				<td class="formcell"><input type="text" name="primarycontactname"
					id="primarycontactname" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Email:</td>
				<td class="formcell"><input type="text" name="primarycontactemail"
					id="primarycontactemail" size="54"></td>
			</tr>
			<tr>
				<td class="labelcell">Telephone:</td>
				<td class="formcell"><input type="text"
					name="primarycontacttelephone" size="54"></td>
			</tr>
			<tr class="separatorrow">
				<td colspan="2"></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" value="Add customer"></td>
			</tr>
		</table>
	</form>
	<?php
	//add the page footer
	include("../inc_files/ui/footer.php");?>
</body>
</html>
